﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AnimalCare.Model;

namespace AnimalCare.Service
{
    class TypeService
    {
        public static void Insert(string typeName)
        {
            TypeProduct cf = new TypeProduct();
            cf.type_name = typeName;
            using (var ctx = new AnimalCareDBEntities())
            {
                ctx.TypeProducts.AddObject(cf);
                ctx.SaveChanges();
            }
        }

        public static void Update(TypeProduct cf)
        {
            using (var ctx = new AnimalCareDBEntities())
            {
                var classification = (from s in ctx.TypeProducts
                                      where s.type_id == cf.type_id
                                      select s).FirstOrDefault();
                classification.type_name = cf.type_name;
                int num = ctx.SaveChanges();
            }
        }

        public static void Delete(int id)
        {
            try
            {
                using (var ctx = new AnimalCareDBEntities())
                {
                    var cf = (from s in ctx.TypeProducts
                              where s.type_id == id
                              select s).FirstOrDefault();
                    ctx.TypeProducts.DeleteObject(cf);
                    int num = ctx.SaveChanges();
                }
            }
            catch
            {
            }
        }
    }
}
